/*!
https://gitee.com/uqbn/labs/raw/master/unit3/main.c
*/
#include "main.h"

static uint16_t count = 0U;
static uint16_t pwm   = 2500U;

int main(void)
{
    TMOD = 0x11;
    TIM0_SET(0x10000U - 10000U);
    SET_BIT(IE, TIM0_INT_ENABLE | TIM1_INT_ENABLE | INT_ENABLE);
    SET_BIT(TCON, TIM0_ENABLE | TIM1_ENABLE);

    for (;;)
    {
    }
}

void timer0() __interrupt(TF0_VECTOR)
{
    TIM0_SET(0x10000U - 10000U);
    TIM1_SET(0x10000U - pwm);

    switch (count++)
    {
    case 100U:
    {
        pwm = 0U;
        break;
    }
    case 200U:
    {
        pwm = 2500U;
        break;
    }
    case 300U:
    {
        pwm = 5000U;
        break;
    }
    case 400U:
    {
        count = 0;

        pwm = 7500U;
        break;
    }

    default:
        break;
    }

    P1 = 0xFFU;
}

void timer1() __interrupt(TF1_VECTOR)
{
    P1 = 0x00U;
}

/* END OF FILE */
